import com.google.gson.Gson;
import com.joolun.common.constant.Constants;
import com.joolun.common.core.redis.RedisCache;
import com.joolun.echart.Option;
import com.joolun.echart.axis.CategoryAxis;
import com.joolun.echart.axis.ValueAxis;
import com.joolun.echart.code.Magic;
import com.joolun.echart.code.MarkType;
import com.joolun.echart.code.Tool;
import com.joolun.echart.code.Trigger;
import com.joolun.echart.data.PointData;
import com.joolun.echart.feature.MagicType;
import com.joolun.echart.json.GsonUtil;
import com.joolun.echart.series.Bar;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: wltay
 * @date: 2021/3/26 16:19
 */
//@SpringBootTest
public class Mytest {



    public static void main(String[] args) {

    }


    @Test
    public void testRedis(){


//        redisCache.setCacheObject(Constants.TEST, "testvalue", Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);


    }


    @Test
    public void test() {
        //地址：http://echarts.baidu.com/doc/example/bar1.html
        Option option = new Option();
        option.title().text("某地区蒸发量和降水量").subtext("纯属虚构");
        option.tooltip().trigger(Trigger.axis);
        option.legend("蒸发量", "降水量");
        option.toolbox().show(true).feature(Tool.mark, Tool.dataView, new MagicType(Magic.line, Magic.bar).show(true), Tool.restore, Tool.saveAsImage);
        option.calculable(true);
        option.xAxis(new CategoryAxis().data("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"));
        option.yAxis(new ValueAxis());

        Bar bar = new Bar("蒸发量");
        bar.data(2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3);
        bar.markPoint().data(new PointData().type(MarkType.max).name("最大值"), new PointData().type(MarkType.min).name("最小值"));
        bar.markLine().data(new PointData().type(MarkType.average).name("平均值"));

        Bar bar2 = new Bar("降水量");
        List<Double> list = Arrays.asList(2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3);
        bar2.data(list.toArray());
        bar2.markPoint().data(new PointData("年最高", 182.2).xAxis(7).yAxis(183).symbolSize(18), new PointData("年最低", 2.3).xAxis(11).yAxis(3));
        bar2.markLine().data(new PointData().type(MarkType.average).name("平均值"));

        option.series(bar, bar2);
//        option.exportToHtml("bar1.html");
//        option.view();

        Gson gson = new Gson();

//        String s = gson.toJson(option);

//        System.out.println(s);

        String format = GsonUtil.format(option);
        System.out.println(format);

        System.out.println("======================================================");
        String format1 = GsonUtil.prettyFormat(option);//格式化完毕的。
        System.out.println(format1);

    }
}
